'use strict';

const Controller = require('egg').Controller;
const qiniu = require('qiniu')


class QiniuController extends Controller {
  async getToken() {
    const { ctx, app: { fullQiniu }, } = this;
    var ak = 'IYe0gw8UokETMTzlSK90sAhZG8uKU4mvtfOrjNoR', // Access Key
      sk = 'PETigMluzETup4-FzOAxrLNVOadaQ73AdHGW3QpY'; // Secret Key
    var options = {
      scope: fullQiniu.bucket,
    };

    var mac = new qiniu.auth.digest.Mac(ak, sk);
    var putPolicy = new qiniu.rs.PutPolicy(options);
    var uptoken = putPolicy.uploadToken(mac);
    const domain = fullQiniu.baseUrl
    this.ctx.body = {
      uptoken,
      upload_qiniu_addr: domain,
      upload_qiniu_url: "http://upload-z1.qiniup.com",
      code: 200
    };

  }
  async delete() {


  }
}

module.exports = QiniuController;
